package bubble;

import java.awt.Color;

import javax.swing.JTextPane;

public class Bubble {

	static void sort(int arr[], JTextPane[] textPane) {
		int temp = 0;
		Color c = new Color(30, 144, 255);
		Color c2 = new Color(218 - 112 - 214);
		Boolean bool = true;
		String str2, str1;
		for (int N = arr.length - 2; N >= 0; N--) {
			for (int i = 0; i <= N; i++) {
				textPane[i].setBackground(Color.lightGray);
				textPane[i + 1].setBackground(Color.lightGray);
				try {
					Thread.sleep(200);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				textPane[i + 1].setBackground(c);
				textPane[i].setBackground(c);
				if (arr[i] > arr[i + 1]) {
					bool = false;
					textPane[i + 1].setBackground(c2);
					textPane[i].setBackground(c2);
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					str1 = Integer.toString(arr[i]);
					str2 = Integer.toString(arr[i + 1]);
					textPane[i].setText(str2);
					textPane[i + 1].setText(str1);
					try {
						Thread.sleep(200);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					textPane[i + 1].setBackground(c);
					textPane[i].setBackground(c);

					temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
				}
			}
			if (bool == true ) break;
		}
	}
}